<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="__ROOT__/static/admin/css/pintuer.css">
    <link rel="stylesheet" href="__ROOT__/static/admin/css/admin.css">
    <link rel="stylesheet" href="__ROOT__/static/admin/css/laydate.css">
    <script src="__ROOT__/static/admin/js/jquery.js"></script>
    <script src="__ROOT__/static/admin/js/pintuer.js"></script>
    <script src="__ROOT__/static/plugins/layer/layer.min.js"></script>
    <script src="__ROOT__/static/admin/js/laydate.js"></script>
    <style>
        .show_file{
            padding: 0px 10px;
            height: 40px;
            line-height: 40px;
            position: relative;
            cursor: pointer;
            color: #fff;
            background: #00AAEE;
            border: 1px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
            display: inline-block;
            *display: inline;
            *zoom: 1
        }

        .show_file input{
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }

        .show_file:hover {
            color: #fff;
            background: #0099CC;
            border-color: #ccc;
            text-decoration: none
        }
    </style>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>添加活动内容</strong></div>
    <div class="body-content">
        <div   class="form-x">
            <div class="form-group">
                <div class="label">
                    <label>标题：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="" id="active_title" data-validate="required:请输入标题" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>图片：</label>
                </div>
                <div class="field">
                    <span id="image"></span>
                    <div class="show_file">
                        <form id="upload" action="" enctype="multipart/form-data">
                            <input type="file" class="button bg-blue margin-left" id= 'active_imgs_url' onchange="upload()" name="img" style="float:left;">
                        </form>
                        <span id="image1">浏览上传</span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="label">
                    <label>内容：</label>
                </div>
                <div class="field">
                    <textarea name="content" class="input" id="active_content" style="height:300px; border:1px solid #ddd;"></textarea>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>活动时间：</label>
                </div>
                <span class="field">
                    <input type="text" class="demo-input" placeholder="请选择开始日期" id="test">
                    <input type="number" style="width: 40px"  value="" id="test1"> 时
                    <input type="number" style="width: 40px"  value="" id="test2"> 分
                    <br/>
                    <br/>
                    <input type="text" class="demo-input" placeholder="请选择结束日期" id="tests">
                    <input type="number" style="width: 40px" value="" id="tests1"> 时
                    <input type="number" style="width: 40px" value="" id="tests2"> 分
                </span>

            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <a class="button bg-main icon-check-square-o" id="btn1" type="submit" onclick="submit()"> 提交</a>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    lay('#version').html('-v'+ laydate.v);

    //执行一个laydate实例
    laydate.render({
        elem: '#test' //指定元素
    });

    laydate.render({
        elem: '#tests' //指定元素
    });

    /*上传图片*/
    function upload() {
        var formData = new FormData($('#upload')[0]);
        $.ajax({
            cache: false,
            type: "POST",
            url: "{:url('admin/Activity/addActivity')}",
            data: formData,
            async: false,
            contentType: false,
            processData: false,
            success: function (data) {
                //把上传路径写到数据库
                var params = {};
                params.active_imgs_url = data;
                $('#image').html('<img style="width: 300px ;height: 300px " id="image_url" src="'+'__ROOT__/'+params.active_imgs_url+'" />');
            }
        });
    }
    // 提交
    function submit() {
        var data = {};
        data.active_title = $('#active_title').val();
        data.active_content = $('#active_content').val();
        data.active_imgs_url = $('#image_url').attr('src');
        data.start_time = $('#test').val()+' '+$('#test1').val()+':'+$('#test2').val()+':'+'00';
        data.over_time = $('#tests').val()+' '+$('#tests1').val()+':'+$('#tests2').val()+':'+'00';
        $.post("{:url('admin/Activity/addActivityList')}",data, function (response) {
            console.dir(response);
            if(response == 1){
                layer.msg('添加成功', {icon: 5});
                window.location.href = "{:url('admin/Activity/index')}";
            }else if(response == 'time'){
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim',
                    area: ['300px', '200px'],
                    content: '<div style="line-height: 140px; text-align: center">'+'<h2>'+'活动未开始,禁止添加活动！'+'</h2>'+'</div>'
                });
            }else {
                layer.msg('添加失败', {icon: 5});
                window.location.href = "{:url('admin/Activity/addActivityView')}";
            }

        });
    }





</script>
</body>
</html>